﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

// Condition: Write program that finds the most frequent number in an array.


class MaxRepeatValue
{
    static void Main()
    {
        // 1. Declare array of N elements and helping variables
        Console.Write("Enter number of elements N: ");
        int N = int.Parse(Console.ReadLine());
        int[] myArr = new int[N];
        Console.WriteLine("Enter elements of integer array: ");
        for (int index = 0; index < N; index++)
        {
            Console.Write("element[{0}]= ", index);
            myArr[index] = int.Parse(Console.ReadLine());
        }
        int value = myArr[0];
        int count;
        int maxCount = 1;
        bool check = false;


        // 2. Two loops to find maxCount and value of element.
        for (int i = 0; i < myArr.Length - 1; i++)
        {
            count = 1;
            for (int j = i + 1; j < myArr.Length; j++)
            {

                if (myArr[j] == myArr[i])
                {
                    check = true;
                    count++;
                }
            }
            if (count > maxCount)
            {
                maxCount = count;
                value = myArr[i];
            }
        }

        // 3. Print the result
        if (check == false)
        {
            Console.WriteLine("There is no repeated element in an array.");
        }
        else
        {
            Console.WriteLine("Elements with value={0} are repeated maximum {1} time in the array.", value, maxCount);
        }

    }
}

